package com.unidt.www.module.bpm.controller.admin.definition;

import com.unidt.www.framework.common.pojo.CommonResult;
import com.unidt.www.module.bpm.dto.ActReActBtnConfigDto;
import com.unidt.www.module.bpm.dto.ActReActTimeConfigDto;
import com.unidt.www.module.bpm.service.task.ActReActConfigService;
import com.unidt.www.module.bpm.vo.ActReActBtnConfigVo;
import com.unidt.www.module.bpm.vo.ActReActDeadTimeConfigVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.unidt.www.framework.common.pojo.CommonResult.success;

/**
 * @Author sk
 * @Description:
 * @Date 2023/2/8 11:13
 **/
@Api(tags = "管理后台 - 流程模型-节点截止时间")
@RestController
@RequestMapping("/bpm/dead-time")
@Validated
public class BpmActDeadTimeConfigController {

    @Autowired
    ActReActConfigService actReActConfigService;

    @GetMapping("/getConfig/{modelId}/{actId}")
    @ApiOperation("获取节点时间设置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modelId", value = "模型ID", required = true, example = "1024", dataTypeClass = String.class),
            @ApiImplicitParam(name = "actId", value = "节点标识ID", required = true, example = "1024", dataTypeClass = String.class)
    })
    public CommonResult<ActReActDeadTimeConfigVo> getConfig(@PathVariable(value = "modelId") String modelId,
                                                            @PathVariable(value = "actId") String actId) {
        return success(actReActConfigService.getBaseTimeConfig(modelId,actId));
    }




    @GetMapping("/getConfig/{processDefinitionId}/{actId}")
    @ApiOperation("获取流程定义-节点时间配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processDefinitionId", value = "流程定义ID", required = true, example = "1024", dataTypeClass = String.class),
            @ApiImplicitParam(name = "actId", value = "节点标识ID", required = true, example = "1024", dataTypeClass = String.class)
    })
    public CommonResult<ActReActDeadTimeConfigVo> getProcessTimeConfig(@PathVariable(value = "processDefinitionId") String processDefinitionId,
                                                              @PathVariable(value = "actId") String actId) {
        return success(actReActConfigService.getProcessTimeConfig(processDefinitionId,actId));
    }

    @PostMapping("/saveTimeConfig")
    @ApiOperation("保存节点时间配置")
    public CommonResult saveTimeConfig(@RequestBody ActReActTimeConfigDto  actReActTimeConfigDto) {
        this.actReActConfigService.saveTimeConfig(actReActTimeConfigDto);
        return CommonResult.from(true);
    }


    @PostMapping("/saveBatchTimeConfig")
    @ApiOperation("批量保存节点时间配置")
    public CommonResult saveBatchTimeConfig(@RequestBody List<ActReActTimeConfigDto> actReActTimeConfigDtoList) {

       return CommonResult.from(this.actReActConfigService.saveBatchTimeConfig(actReActTimeConfigDtoList));

    }

}
